package com.example.commonlib.listener;

import android.util.Log;
import android.view.View;

import java.util.Calendar;

/**
 * Created by zxw.
 * Date: 2019/12/6 16:19
 * Description: 屏蔽快速点击
 */
public abstract class NoDoubleClickListener implements View.OnClickListener {
    /**
     * TAG
     */
    private static final String TAG = "NoDoubleClickListener";
    /**
     * 点击时延
     */
    private static final int MIN_CLICK_DELAY_TIME = 500;

    /**
     * 最后点击时间
     */
    private long lastClickTime = 0;

    @Override
    public void onClick(View v) {
        long currentTime = Calendar.getInstance().getTimeInMillis();
        if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) {
            lastClickTime = currentTime;
            onNoDoubleClick(v);
        } else {
            Log.w(TAG, "Don't click too fast ！");
        }
    }

    /**
     * onNoDoubleClick
     *
     * @param v view
     */
    public abstract void onNoDoubleClick(View v);

}
